import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types';
import { getWeekMonthQuarterYear } from '/@/utils';
import { hasScopePlaceholder } from 'unocss';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '售后单id',
    align: 'center',
    dataIndex: 'asId',
    ifShow: false,
  },
  {
    title: '售后单',
    align: 'center',
    dataIndex: 'asCode',
    width: 100,
    ifShow: false,
  },
  {
    title: '售后单',
    align: 'left',
    dataIndex: 'asCodeInfo',
    width: 90,
    slots: { customRender: 'asCodeRender' },
    resizable: false,
  },
  {
    title: '售后单状态',
    align: 'center',
    dataIndex: 'asStatus',
    width: 100,
    ifShow: false,
    //slots: { customRender: 'asStatusRender' },
  },
  {
    title: '售后凭证',
    align: 'center',
    dataIndex: 'applyAttachments',
    customRender: render.renderImage,
    width: 150,
  },

  {
    title: '售后数据',
    align: 'left',
    dataIndex: 'asData',
    width: 90,
    slots: { customRender: 'asDataRender' },
    resizable: true,
  },
  {
    title: '售后商品总数量',
    align: 'center',
    dataIndex: 'productTotalQuantity',
    ifShow: false,
  },
  {
    title: '售后商品种数',
    align: 'center',
    dataIndex: 'productCategoryCount',
    ifShow: false,
  },
  {
    title: '售后总金额',
    align: 'center',
    dataIndex: 'productTotalAmount',
    ifShow: false,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '售后工单号',
    field: 'workorder',
    component: 'JInput',
  },
  {
    label: '订单编号',
    field: 'orderCode',
    component: 'JInput',
  },
  {
    label: '门店编号',
    field: 'storeCode',
    component: 'JInput',
  },
  {
    label: '售后单状态',
    field: 'woStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'audit_state',
    },
  },
];

//子表表格
export const subColumns: BasicColumn[] = [
  {
    title: '主图',
    dataIndex: 'mainPic',
    width: '50px',
    customRender: render.renderImage,
  },
  {
    title: 'upc_code',
    dataIndex: 'upcCode',
    width: '150px',
  },
  {
    title: '商品名称',
    align: 'center',
    dataIndex: 'productName',
  },
  {
    title: '产品价格',
    align: 'center',
    dataIndex: 'productPrice',
  },
  {
    title: '售后数量',
    align: 'center',
    dataIndex: 'aftersaleQuantity',
  },
  {
    title: '售后金额',
    align: 'center',
    dataIndex: 'aftersaleAmount',
  },
  {
    title: '售后原因',
    align: 'center',
    dataIndex: 'reason_dictText',
  },
];
//子表表格配置
export const xlCustomerAftersaleDetailColumns: JVxeColumn[] = [
  {
    title: '主图',
    key: 'mainPic',
    type: JVxeTypes.image,
    width: '50px',
  },
  {
    title: 'upc_code',
    key: 'upcCode',
    type: JVxeTypes.normal,
    width: '150px',
  },
  {
    title: '商品名称',
    key: 'productName',
    type: JVxeTypes.normal,
    width: '200px',
  },
  {
    title: '产品价格',
    key: 'productPrice',
    type: JVxeTypes.normal,
    width: '100px',
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '订单数量',
    key: 'orderQuantity',
    type: JVxeTypes.normal,
    width: '120px',
  },
  {
    title: '订单金额',
    key: 'orderAmount',
    type: JVxeTypes.normal,
    width: '120px',
  },
  {
    title: '售后数量',
    key: 'aftersaleQuantity',
    type: JVxeTypes.inputNumber,
    width: '120px',
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [
      {
        handler({ cellValue, row, column }, callback, target) {
          if (Number(cellValue) <= 0) {
            //callback(false, '${title}不能小于等于0'); 如果不填或作写0表示无售后
          }
          if (Number(cellValue) > Number(row['orderQuantity'])) {
            callback(false, '${title}不能大于订单数量');
          } else {
            callback(true); // true = 通过验证
          }
        },
        message: '${title}默认提示',
      },
    ],
  },
  {
    title: '售后金额',
    key: 'aftersaleAmount',
    type: JVxeTypes.normal,
    width: '120px',
    placeholder: '请输入${title}',
    defaultValue: '',
  },
  {
    title: '售后原因',
    key: 'reason',
    type: JVxeTypes.select,
    dictCode: 'slt_aftersale_renson',
    placeholder: '请输入${title}',
    defaultValue: '',
    validateRules: [
      {
        handler({ cellValue, row, column }, callback, target) {
          if (row.aftersaleAmount > 0) {
            if (!cellValue) {
              callback(false, '${title} 必填');
            } else callback(true);
          } else callback(true);
        },
        message: '${title}默认提示',
      },
    ],
  },
];

//审批表单
export const auditFormSchema: FormSchema[] = [
  {
    label: '审批状态',
    field: 'asStatus',
    component: 'JDictSelectTag',
    componentProps: {
      options: [
        { value: '同意', label: '同意' },
        { value: '拒绝', label: '拒绝' },
      ],
      type: 'radioButton',
    },
    defaultValue: '拒绝',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请选择审批状态!' }];
    },
  },
  {
    label: '确认退款金额',
    field: 'refundAmount',
    component: 'InputNumber',
    componentProps: {},
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '退款金额!' }];
    },
  },
  {
    label: '审核说明',
    field: 'rejectReason',
    component: 'InputTextArea',
    //属性
    componentProps: {
      //可以点击清除图标删除内容
      allowClear: true,
      //是否展示字数
      showCount: true,
      //自适应内容高度，可设置为 true | false 或对象：{ minRows: 2, maxRows: 6 }
      autoSize: {
        //最小显示行数
        minRows: 2,
        //最大显示行数
        maxRows: 3,
      },
    },
    required: ({ values }) => {
      return values.asStatus === '拒绝';
    },
  },
  {
    label: '',
    field: 'asId',
    component: 'Input',
    show: true,
  },
];
